package com.epfresh.supplier.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.api.constant.AppSupplyRouterConstant;
import com.epfresh.api.entity.RequestEntityMapSupply;
import com.epfresh.api.entity.RequestTag;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.global.BaseApplication;
import com.epfresh.api.global.BaseFragment;
import com.epfresh.api.global.DataManager;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.api.utils.DateUtil;
import com.epfresh.api.utils.JsonUtils;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.api.utils.T;
import com.epfresh.api.widget.Dialog.BaseDialogView;
import com.epfresh.api.widget.MsgView;
import com.epfresh.api.widget.ptr.PtrDefaultHandler;
import com.epfresh.api.widget.ptr.PtrFrameLayout;
import com.epfresh.api.widget.ptr.PtrHandler;
import com.epfresh.api.widget.tablayout.utils.UnreadMsgUtils;
import com.epfresh.supplier.R;
import com.epfresh.supplier.activity.BookActivity;
import com.epfresh.supplier.activity.ChangePriceActivity;
import com.epfresh.supplier.activity.CustomerInfoActivity;
import com.epfresh.supplier.activity.GoodsStockActivity;
import com.epfresh.supplier.activity.H5OrderDetailActivity;
import com.epfresh.supplier.activity.H5StoreDecorateActivity;
import com.epfresh.supplier.activity.HomeActivity;
import com.epfresh.supplier.activity.JoinPrepareListActivity;
import com.epfresh.supplier.activity.JoinPriceActivity;
import com.epfresh.supplier.activity.MoreEvaluateActivity;
import com.epfresh.supplier.activity.MyCouponActivity;
import com.epfresh.supplier.activity.OfferListActivity;
import com.epfresh.supplier.activity.OrderMinusDetailActivity;
import com.epfresh.supplier.activity.OrderMinusListActivity;
import com.epfresh.supplier.activity.OrderMoreActivity;
import com.epfresh.supplier.activity.ProductActivity;
import com.epfresh.supplier.activity.StoreActivity;
import com.epfresh.supplier.activity.StoreEnsureAndOpenActivity;
import com.epfresh.supplier.activity.employ.EmployManageActivity;
import com.epfresh.supplier.activity.standingbook.DebtActivity;
import com.epfresh.supplier.activity.standingbook.StandingBookActivity;
import com.epfresh.supplier.adapter.HomeHeaderViewBinder;
import com.epfresh.supplier.adapter.OrderAuthViewBinder;
import com.epfresh.supplier.adapter.OrderStoreViewBinder;
import com.epfresh.supplier.constant.Constant;
import com.epfresh.supplier.dialog.HomePriceNoticeDialog;
import com.epfresh.supplier.dialog.MerchantListDialog;
import com.epfresh.supplier.entity.AuthStatus;
import com.epfresh.supplier.entity.ContentEntity;
import com.epfresh.supplier.entity.MerChantInfo;
import com.epfresh.supplier.entity.MerchantMember;
import com.epfresh.supplier.entity.OrderStoreDyn;
import com.epfresh.supplier.entity.PriceNoticeEntity;
import com.epfresh.supplier.entity.StaffInfo;
import com.epfresh.supplier.widget.ViewVariable;
import com.google.gson.Gson;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import multitype.MultiTypeAdapter;
import multitype.OnRecyclerViewItemClickListener;
import multitype.loadmore.LoadMoreDelegate;
import multitype.loadmore.LoadMoreItem;
import multitype.loadmore.LoadMoreViewBinder;


/**
 * Created by wzh on 2016/5/4.
 */
public class HomePageFragment extends BaseFragment implements ViewVariable {

    //列表数据
    List<Object> mItems = new ArrayList<>();

    //权限数据
    List<AuthStatus> mAuthStatuses = new ArrayList<>();

    List<OrderStoreDyn> mOrderStoreDyns = new ArrayList<>();

    MultiTypeAdapter mMultiAdapter;

    OrderStoreViewBinder orderStoreViewBinder;
    OrderAuthViewBinder orderAuthViewBinder;

    GridLayoutManager mManager;

    RecyclerView rv;

    View vToolbar;
    View vTitleTop;
    private TextView tvTitle;
    private ImageView ivTitleFlag;
    View vTop;

    ImageView ivEditPriceLitter;
    ImageView ivPrepareLitter;
    ImageView ivOfferLitter;
    ImageView ivWriteOffLitter;

    TextView tvEditPrice;
    TextView tvPrepare;
    TextView tvPrepareHint;
    TextView tvOfferGet;

    TextView tvWriteOff;
    TextView tvIntoStore;

    LoadMoreDelegate loadMoreDelegate = new LoadMoreDelegate();
    private int updateJoinPrice = -1;//联营报价小红点显示判断


    MsgView msgPrice;
    TextView msgOffer;
    int pageNum = -1;

    View rlOffer;
    private LoadMoreDelegate.LoadMoreSubject loadMoreSubject = new LoadMoreDelegate.LoadMoreSubject() {
        @Override
        public boolean canLoad() {
            return !ptrFrameLayout.isRefreshing() && pageNum > -1;
        }

        @Override
        public void onLoadMore() {
//            loadMoreDelegate.setStatusLoading();
            reqSupplyStoreDyn(pageNum + 1);

        }
    };

    public void updateMsgPrice(int cnt) {
        if (cnt > 0) {
            UnreadMsgUtils.show(msgPrice, 0, true, true);
            UnreadMsgUtils.setSize(msgPrice, LocalDisplay.dp2px(9));
        } else {
            msgPrice.setVisibility(View.GONE);
        }
    }

    public void updateMsgOffer(int cnt) {
        if (cnt > 0) {
            msgOffer.setText(""+cnt);
            msgOffer.setVisibility(View.VISIBLE);
            Log.e("_______",""+cnt);
            /*UnreadMsgUtils.show(msgOffer, cnt, true, true);
            UnreadMsgUtils.setSize(msgOffer, LocalDisplay.dp2px(12));*/
        } else {
            msgOffer.setVisibility(View.GONE);
        }
    }


    @Override
    public String getBaseTag() {
        return Constant.TAG_HOME_FRAGMENT;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_home_page,
                container, false);
    }

    private PtrFrameLayout ptrFrameLayout;
    private PtrHandler ptrHandler = new PtrHandler() {
        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return PtrDefaultHandler.checkContentCanBePulledDown(frame, rv, header);
        }

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
            reqMerchantList();
        }

    };

    private void initHeadView(View v) {
        ptrFrameLayout = (PtrFrameLayout) v.findViewById(R.id.fragment_ptr_home_ptr_frame);
        ptrFrameLayout.setPtrHandler(ptrHandler);
    }

    @Override
    public void onViewCreated(View v, Bundle savedInstanceState) {
        super.onViewCreated(v, savedInstanceState);

        initHeadView(v);
        initNotice();
        rlOffer = v.findViewById(R.id.rl_offer);
        msgPrice = (MsgView) v.findViewById(R.id.msg_change_price);
        msgOffer = (TextView) v.findViewById(R.id.msg_offer_get);
        rv = (RecyclerView) v.findViewById(R.id.rv);

        vToolbar = v.findViewById(R.id.rl_litter_title);

        vTop = v.findViewById(R.id.rl_top);
        vTitleTop = v.findViewById(R.id.ll_title_top);
        tvTitle = (TextView) v.findViewById(R.id.tv_expend_title);

        tvEditPrice = (TextView) v.findViewById(R.id.tv_edit_price);
        tvPrepare = (TextView) v.findViewById(R.id.tv_prepare);
        tvPrepareHint = v.findViewById(R.id.tv_prepare_hint);
        tvOfferGet = (TextView) v.findViewById(R.id.tv_offer_get);
        tvWriteOff = (TextView) v.findViewById(R.id.tv_write_off);
        tvIntoStore = (TextView) v.findViewById(R.id.tv_into_store);
        ivEditPriceLitter = (ImageView) v.findViewById(R.id.iv_edit_price_litter);
        ivPrepareLitter = (ImageView) v.findViewById(R.id.iv_prepare_litter);
        ivOfferLitter = (ImageView) v.findViewById(R.id.iv_offer_litter);
        ivWriteOffLitter = (ImageView) v.findViewById(R.id.iv_write_off_litter);
        ivTitleFlag = (ImageView) v.findViewById(R.id.iv_filter);
        tvTitle.setText("");
        vTitleTop.setVisibility(View.GONE);
        vTitleTop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                expendTitle();
            }
        });

        tvIntoStore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intoStore();
            }
        });

        tvEditPrice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intoEditPrice();
            }
        });
        tvPrepare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intoJoinPrepare();
            }
        });
        tvOfferGet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intoOffer();
            }
        });

        tvWriteOff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intoWriteOff();
            }
        });

        ivEditPriceLitter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intoEditPrice();
            }
        });

        ivPrepareLitter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intoJoinPrepare();
            }
        });

        ivOfferLitter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intoOffer();
            }
        });

        ivWriteOffLitter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                intoWriteOff();
            }
        });
        mManager = new GridLayoutManager(getContext(), 4) {
            @Override
            public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {

                try {
                    super.onLayoutChildren(recycler, state);
                } catch (Exception e) {

                    e.printStackTrace();
                }

            }
        };
        GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                Object item = mItems.get(position);
                return (item instanceof AuthStatus) ? 1 : 4;
            }
        };
        mManager.setSpanSizeLookup(spanSizeLookup);
        mManager.setSmoothScrollbarEnabled(true);
//        mManager.setOrientation(LinearLayoutManager.VERTICAL);
        rv.setLayoutManager(mManager);

        mMultiAdapter = new MultiTypeAdapter();
        LoadMoreViewBinder loadMoreViewBinder = loadMoreDelegate.getLoadMoreViewBinder();
        loadMoreDelegate.attach(rv, loadMoreSubject);

        orderStoreViewBinder = new OrderStoreViewBinder();
        orderAuthViewBinder = new OrderAuthViewBinder();

        mMultiAdapter.register(LoadMoreItem.class, loadMoreViewBinder);
        mMultiAdapter.register(OrderStoreDyn.class, orderStoreViewBinder);
        mMultiAdapter.register(AuthStatus.class, orderAuthViewBinder);
        mMultiAdapter.register(Integer.class, new HomeHeaderViewBinder());
        mItems.add(new Integer(0));
        rv.setAdapter(mMultiAdapter);
        mMultiAdapter.setItems(mItems);


        rv.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
                // 当不滚动时
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    //获取最后一个完全显示的ItemPosition
                    int index = manager.findFirstCompletelyVisibleItemPosition();
                    if (index == 0) {
                        float alpha = 0;
                        float alpha2 = 1;
                        float alpha3 = 1;


                        if (alpha2 < 0.001) {
                            vTitleTop.setVisibility(View.GONE);

                        } else {
                            vTitleTop.setVisibility(View.VISIBLE);

                        }
                        if ((1 - alpha2) < 0.001) {
                            vToolbar.setVisibility(View.GONE);
                        } else {
                            vToolbar.setVisibility(View.VISIBLE);
                        }

                        ivEditPriceLitter.setAlpha(alpha);
                        ivPrepareLitter.setAlpha(alpha);
                        ivOfferLitter.setAlpha(alpha);
                        ivWriteOffLitter.setAlpha(alpha);

                        vToolbar.setAlpha(1 - alpha2);

                        vTitleTop.setAlpha(alpha2);


                        if (!BaseApplication.getInstance().getMerchant().isEditPrice() || BaseApplication.getInstance().getMerchant().isAuthNeedBind()) {
                            tvEditPrice.setAlpha(0.4f);
                        } else {
                            tvEditPrice.setAlpha(alpha3);
                        }

                        if (!BaseApplication.getInstance().getMerchant().isJoinPrepare()) {
                            tvPrepare.setAlpha(0.4f);
                            tvPrepareHint.setVisibility(View.GONE);
                        } else {
                            tvPrepare.setAlpha(alpha3);
                        }

                        if (!BaseApplication.getInstance().getMerchant().hasOfferAuth()) {
                            tvOfferGet.setAlpha(0.4f);
                        } else {
                            tvOfferGet.setAlpha(alpha3);
                        }

                        if (!BaseApplication.getInstance().getMerchant().isWriteOff()) {
                            tvWriteOff.setAlpha(0.4f);
                        } else {
                            tvWriteOff.setAlpha(alpha3);
                        }
                    }
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);

                vTop.scrollBy(0, (int) (dy * 1));

                int scrollY = vTop.getScrollY();

                float h = LocalDisplay.dp2px(160);

                float h2 = h / 4;
                float alpha = 0;
                float alpha2 = 1;
                float alpha3 = 1;

                if (scrollY > h - h2) {
                    alpha3 = 0;
                } else {
                    alpha3 = 1 - (scrollY - h2) / (h - h2);
                }

                if (scrollY > h2) {
                    alpha2 = 0;
                } else {
                    alpha2 = 1 - scrollY / h2;
                }


                if (scrollY >= h) {
                    alpha = 1;
                } else if (scrollY >= h2) {
                    alpha = (scrollY - h2) / (h - h2);

                }

                if (alpha2 < 0.001) {
                    vTitleTop.setVisibility(View.GONE);

                } else {
                    vTitleTop.setVisibility(View.VISIBLE);

                }
                if ((1 - alpha2) < 0.001) {
                    vToolbar.setVisibility(View.GONE);
                } else {
                    vToolbar.setVisibility(View.VISIBLE);
                }

                ivEditPriceLitter.setAlpha(alpha);
                ivPrepareLitter.setAlpha(alpha);
                ivOfferLitter.setAlpha(alpha);
                ivWriteOffLitter.setAlpha(alpha);

                vToolbar.setAlpha(1 - alpha2);

                vTitleTop.setAlpha(alpha2);


                if (!BaseApplication.getInstance().getMerchant().isEditPrice() || BaseApplication.getInstance().getMerchant().isAuthNeedBind()) {
                    tvEditPrice.setAlpha(0.4f);
                } else {
                    tvEditPrice.setAlpha(alpha3);
                }
                if (!BaseApplication.getInstance().getMerchant().isJoinPrepare()) {
                    tvPrepare.setAlpha(0.4f);
                    tvPrepareHint.setVisibility(View.GONE);
                } else {
                    tvPrepare.setAlpha(alpha3);
                }

                if (!BaseApplication.getInstance().getMerchant().hasOfferAuth()) {
                    tvOfferGet.setAlpha(0.4f);
                } else {
                    tvOfferGet.setAlpha(alpha3);
                }

                if (!BaseApplication.getInstance().getMerchant().isWriteOff()) {
                    tvWriteOff.setAlpha(0.4f);
                } else {
                    tvWriteOff.setAlpha(alpha3);
                }
            }
        });

        orderStoreViewBinder.setOnRecyclerViewItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object data) {
                if (!"4".equals(BaseApplication.getInstance().getMerchant().getStoreStatus())) {
                    if (data != null && data instanceof OrderStoreDyn) {
                        onEventOrderItem((OrderStoreDyn) data);
                    }
                }
            }
        });
        orderAuthViewBinder.setOnRecyclerViewItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object data) {

                if (data != null && data instanceof AuthStatus) {
                    onEventOrderAuthItem((AuthStatus) data);
                }
            }
        });
        updateToolbarTitle();

        updateOnlyHead();

        reqMerchantList();
    }

    public void updateTopInit() {
        if (mItems.size() > 0)
            mManager.scrollToPosition(0);
        vTop.scrollTo(0, 0);
        float alpha = 0;
        float alpha2 = 1;
        float alpha3 = 1;


        if (alpha2 < 0.001) {
            vTitleTop.setVisibility(View.GONE);

        } else {
            vTitleTop.setVisibility(View.VISIBLE);

        }
        if ((1 - alpha2) < 0.001) {
            vToolbar.setVisibility(View.GONE);
        } else {
            vToolbar.setVisibility(View.VISIBLE);
        }

        ivEditPriceLitter.setAlpha(alpha);
        ivPrepareLitter.setAlpha(alpha);
        ivOfferLitter.setAlpha(alpha);
        ivWriteOffLitter.setAlpha(alpha);

        vToolbar.setAlpha(1 - alpha2);

        vTitleTop.setAlpha(alpha2);


        if (!BaseApplication.getInstance().getMerchant().isEditPrice() || BaseApplication.getInstance().getMerchant().isAuthNeedBind()) {
            tvEditPrice.setAlpha(0.4f);
        } else {
            tvEditPrice.setAlpha(alpha3);
        }
        if (!BaseApplication.getInstance().getMerchant().isJoinPrepare()) {
            tvPrepare.setAlpha(0.4f);
            tvPrepareHint.setVisibility(View.GONE);
        } else {
            tvPrepare.setAlpha(alpha3);
        }
        if (!BaseApplication.getInstance().getMerchant().hasOfferAuth()) {
            tvOfferGet.setAlpha(0.4f);
        } else {
            tvOfferGet.setAlpha(alpha3);
        }

        if (!BaseApplication.getInstance().getMerchant().isWriteOff()) {
            tvWriteOff.setAlpha(0.4f);
        } else {
            tvWriteOff.setAlpha(alpha3);
        }
    }


    public void updateInfo() {
        reqMerchantList();
    }

    protected void onEventOrderAuthItem(AuthStatus as) {
        String key = as.getKey();
         /* 我要买    root.app.supplier.buy
            店铺装修    root.app.supplier.store.decoration
            店铺管理    root.app.supplier.store
            消息推送    root.app.supplier.push_message
            员工管理    root.app.supplier.employee
            客户管理    root.app.supplier.customer
            我的收入    root.app.supplier.income
            我的台帐    root.app.supplier.standing_book
            评价       root.app.supplier.comment
            优惠券     root.app.supplier.coupon
            减免退     root.app.supplier.order.jmt
            变价/进货  root.app.supplier.product.price_and_purchase
            预售商品   root.app.supplier.product.presell
            现货商品   root.app.supplier.product.selling
            销售订单   root.app.supplier.order */


        //店铺装修    root.app.supplier.store.decoration
        if ("root.app.supplier.store.decoration".equals(key)) {

            intoDecorate(as);
        }
        // 店铺管理    root.app.supplier.store
        else if ("root.app.supplier.store".equals(key)) {

            intoStore(as);
        }
        //  员工管理    root.app.supplier.employee

        else if ("root.app.supplier.employee".equals(key)) {

            intoEmployee(as);
        }

        //  客户管理    root.app.supplier.customer

        else if ("root.app.supplier.customer".equals(key)) {

            intoCustomer(as);
        }
        //  我的收入    root.app.supplier.income

        else if ("root.app.supplier.income".equals(key)) {

            intoIncome(as);
        }

        //  我的台帐    root.app.supplier.standing_book

        else if ("root.app.supplier.standing_book".equals(key)) {

            intoStandBook(as);
        }
        //  评价       root.app.supplier.comment

        else if ("root.app.supplier.comment".equals(key)) {

            intoComment(as);
        }
        //  优惠券     root.app.supplier.coupon

        else if ("root.app.supplier.coupon".equals(key)) {

            intoCoupon(as);
        }
        // 减免退     root.app.supplier.order.jmt

        else if ("root.app.supplier.order.jmt".equals(key)) {

            intoJMT(as);
        }

        //预售商品   root.app.supplier.product.presell

        else if ("root.app.supplier.product.presell".equals(key)) {

            intoPreSelling(as);
        }
        // 现货商品   root.app.supplier.product.selling

        else if ("root.app.supplier.product.selling".equals(key)) {

            intoSelling(as);
        }
        // 销售订单   root.app.supplier.order
        else if ("root.app.supplier.order".equals(key)) {

            intoSaleOrder(as);
        }
        // 联营报价   root.app.supplier.order
        else if ("root.app.supplier.joint.product".equals(key)) {

            intoJoinPrice();
        }
        // 进货   root.app.supplier.order
        else if ("root.app.supplier.product.purchase".equals(key)) {
            intoStock();
        }
    }

    protected void toastAuth() {

        MerChantInfo merchant = BaseApplication.getInstance().getMerchant();

        String storeStatus = merchant.getStoreStatus();

        //0,未开,1,开店,2,过,3,未过,4,冻结

        if ("0".equals(storeStatus)) {
            T.toast("请去开店");
        } else if ("1".equals(storeStatus)) {
            T.toast("开店中,暂时无法使用");
        } else if ("2".equals(storeStatus)) {
            if (merchant.isAuthNeedBind()) {
                T.toast("暂无权限");
            }else {
                T.toast("还未开通该权限");
            }
        } else if ("3".equals(storeStatus)) {
            T.toast("店铺未通过审核");
        } else if ("4".equals(storeStatus)) {
            T.toast("店铺已冻结");
        }

    }

    //联营备货
    protected void intoJoinPrepare() {
        if (!BaseApplication.getInstance().getMerchant().isJoinPrepare()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), JoinPrepareListActivity.class);
        startActivityForResult(intent, 0x002);
    }
    //联营报价
    protected void intoJoinPrice() {
        if (!BaseApplication.getInstance().getMerchant().isJoinPrice()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), JoinPriceActivity.class);
        startActivityForResult(intent, 0x002);
    }

    //变价/进货   暂时为商品已上架列表
    protected void intoEditPrice() {
        if (!BaseApplication.getInstance().getMerchant().isEditPrice() || BaseApplication.getInstance().getMerchant().isAuthNeedBind()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), ChangePriceActivity.class);
        startActivityForResult(intent, 0x002);
    }

    //进货   暂时为商品已上架列表
    protected void intoStock() {
        if (!BaseApplication.getInstance().getMerchant().hasStockAuth() || BaseApplication.getInstance().getMerchant().isAuthNeedBind()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), GoodsStockActivity.class);
        startActivity(intent);
    }

    //抢单
    protected void intoOffer() {
        if (!BaseApplication.getInstance().getMerchant().hasOfferAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), OfferListActivity.class);
        startActivity(intent);
    }

    //收款
    protected void intoWriteOff() {
        if (!BaseApplication.getInstance().getMerchant().isWriteOff()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), DebtActivity.class);
        startActivity(intent);
        //T.toast("收款");
    }

    //销售订单
    protected void intoSaleOrder(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), OrderMoreActivity.class);
        intent.putExtra(Constant.TYPE, 5);
        startActivity(intent);
    }

    //现货商品
    protected void intoSelling(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), ProductActivity.class);
        intent.putExtra("productType", 1);
        startActivity(intent);
    }

    //预售商品
    protected void intoPreSelling(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), ProductActivity.class);
        intent.putExtra("productType", 2);
        startActivity(intent);
    }

    //我的台帐
    protected void intoStandBook(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), StandingBookActivity.class);
        startActivity(intent);
    }

    //我的收入
    protected void intoIncome(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), BookActivity.class);
        startActivity(intent);
    }

    //店铺管理
    protected void intoStore(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }

        MerChantInfo merchant = BaseApplication.getInstance().getMerchant();
        String id = merchant.getId();
        String storeStatus = merchant.getStoreStatus();
        if (id == null || "".equals(id) || "0".equals(storeStatus)) {
            Intent i = new Intent(getContext(), StoreActivity.class);
            i.putExtra(Constant.KEY_STORE_TYPE_STATUS, Constant.TYPE_STORE_STATUS_FIRST_OPEN);
            startActivity(i);
        } else {

            Intent intent = new Intent(getAppActivity(), StoreEnsureAndOpenActivity.class);
            //intent.putExtra(Constant.KEY_TYPE_STORE_STATUS, TYPE_STROE);
//            intent.putExtra(Constant.KEY_TYPE_CER_STATUS, TYPE_CER);
            intent.putExtra("cert_status", storeStatus);
            intent.putExtra("cert_type", storeStatus);
            intent.putExtra("card_count", "1");
            //是否需要对Store判空尚不太确定；
           /* if (storeInfo.getStore() == null || storeInfo.getStore().getAuditStatus() == null) {
                intent.putExtra("audit_status", "");
            } else {
                intent.putExtra("audit_status", storeInfo.getStore().getAuditStatus());
            }*/
            startActivity(intent);
        }


    }

    //店铺管理
    protected void intoStore() {

        Intent i = new Intent(getContext(), StoreActivity.class);
        i.putExtra(Constant.KEY_STORE_TYPE_STATUS, Constant.TYPE_STORE_STATUS_FIRST_OPEN);
        startActivity(i);
    }

    //客户管理
    protected void intoCustomer(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent customer = new Intent(getAppActivity(), CustomerInfoActivity.class);
        customer.setAction(HOME_ACTIVITY);
        startActivity(customer);
    }

    //店铺装修
    protected void intoDecorate(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getContext(), H5StoreDecorateActivity.class);

        intent.putExtra(Constant.KEY_WEB_URL, "http://180.168.156.212:2135/jdzg-gh-app/1.0.0/index/index.html#/nav/5");//+BaseApplication.getInstance().getStoreId());
        intent.putExtra(Constant.KEY_WEB_TITLE, "店铺装修");
        Log.e("url____", "http://180.168.156.212:2135/jdzg-gh-app/1.0.0/index/index.html#/nav/5");//+BaseApplication.getInstance().getStoreId());
                               /*180.168.156.212:2135/jdzg-gh-app/1.0.0/index/index.html#/nav/284*/
        startActivity(intent);
        //T.toast("店铺装修");
    }

    //员工管理
    protected void intoEmployee(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), EmployManageActivity.class);
        startActivity(intent);
    }

    //减免退
    protected void intoJMT(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), OrderMinusListActivity.class);
        intent.putExtra(Constant.TYPE, 3);
        startActivity(intent);
    }

    //评价
    protected void intoComment(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent intent = new Intent(getAppActivity(), MoreEvaluateActivity.class);
        startActivity(intent);
    }

    //优惠券
    protected void intoCoupon(AuthStatus as) {
        if (!as.isAuth()) {
            toastAuth();
            return;
        }
        Intent coupons = new Intent(getAppActivity(), MyCouponActivity.class);
        startActivity(coupons);
    }


    protected void onEventOrderItem(OrderStoreDyn osd) {
        String type = osd.getType();


        DataManager.getInstance().isNoRefreshSell = true;
        //订单
        if ("ORDER".equals(type)) {
            intoOrder(osd);
        } else if ("JMT".equals(type)) {//减免退
            intoJMT(osd);
        } else if ("COMMENT".equals(type)) {//评论
            intoComment(osd);
        } else if ("PLATFORM".equals(type)) {//台账
            intoStandBook(osd);
        }
    }

    //订单
    protected void intoOrder(OrderStoreDyn osd) {
//        T.toast("订单");
        Intent detail = new Intent(getContext(), H5OrderDetailActivity.class);
        detail.putExtra("orderId", osd.getObjectId());
        detail.putExtra(com.epfresh.api.constant.Constant.KEY_WEB_URL, "http://m.epfresh.com/help/order_supply_new.html?orderId=" + osd.getObjectId());
        detail.putExtra(com.epfresh.api.constant.Constant.KEY_WEB_TITLE, "订单详情");
        startActivity(detail);

    }

    //减免退
    protected void intoJMT(OrderStoreDyn osd) {
        if (osd == null) {
            return;
        }
        //   T.toast("减免退");
        MerChantInfo merchant = BaseApplication.getInstance().getMerchant();
        if (merchant == null) {
            return;
        }

        Boolean isAuth = merchant.getResources("root.app.supplier.order.jmt");
        if (isAuth != null && isAuth) {

            Intent intent = new Intent(getAppActivity(), OrderMinusDetailActivity.class);
            intent.putExtra("id", osd.getObjectId());
            startActivity(intent);
        }
    }

    //评论
    protected void intoComment(OrderStoreDyn osd) {

        //   T.toast("评论");
        MerChantInfo merchant = BaseApplication.getInstance().getMerchant();
        if (merchant == null) {
            return;
        }

        Boolean isAuth = merchant.getResources("root.app.supplier.comment");
        if (isAuth != null && isAuth) {

            Intent intent = new Intent(getAppActivity(), MoreEvaluateActivity.class);
            startActivity(intent);
        }
    }

    //台账
    protected void intoStandBook(OrderStoreDyn osd) {
        //    T.toast("台账");

        MerChantInfo merchant = BaseApplication.getInstance().getMerchant();
        if (merchant == null) {
            return;
        }

        Boolean isAuth = merchant.getResources("root.app.supplier.standing_book");
        if (isAuth != null && isAuth) {

            Intent intent = new Intent(getAppActivity(), StandingBookActivity.class);
            startActivity(intent);
        }
    }


    protected void updateOnlyHead() {
        mItems.clear();
        mItems.add(new Integer(0));
        mItems.addAll(mAuthStatuses);
        mMultiAdapter.notifyDataSetChanged();
    }

    public void updateMerchantInfo(MerChantInfo merChantInfo) {
        if(merChantInfo.isAuthNeedBind()){//true 散货 false 整货
            rlOffer.setVisibility(View.GONE);
            ivOfferLitter.setVisibility(View.GONE);
        }else {
            rlOffer.setVisibility(View.VISIBLE);
            ivOfferLitter.setVisibility(View.VISIBLE);
        }


        mAuthStatuses.clear();
        if (merChantInfo != null) {
            List<AuthStatus> authStatus = merChantInfo.getAuthStatus();

            mAuthStatuses.addAll(authStatus);
            for(int i=mAuthStatuses.size()-1;i>0;i--){
                if (mAuthStatuses.get(i).getKey().equals("root.app.supplier.joint.product")) {
                    if (updateJoinPrice != -1) {
                        mAuthStatuses.get(i).setUpdateJoinPrice(updateJoinPrice);
                    }
                }

                if (mAuthStatuses.get(i).getKey()=="root.app.supplier.buy"||mAuthStatuses.get(i).getKey()=="root.app.supplier.sell"||mAuthStatuses.get(i).getKey()=="root.app.supplier.store.decoration")
                    mAuthStatuses.remove(i);
            }
            int size = mAuthStatuses.size();
            int j = size % 4;
            if (j > 0) {
                j = 4 - j;
                for (int i = 0; i < j; i++) {
                    AuthStatus as = new AuthStatus();
                    as.setEmpty(true);
                    mAuthStatuses.add(as);
                }
            }


        }
    }

    public void updateAuthIcon() {


        mAuthStatuses.clear();
        ArrayList<String> merchantDisabledResources = BaseApplication.getInstance().getMerchantDisabledResources();
        List<AuthStatus> authStatus = MerChantInfo.getAuthStatusAll(merchantDisabledResources);

        mAuthStatuses.addAll(authStatus);

        for(int i=mAuthStatuses.size()-1;i>0;i--){
            if (mAuthStatuses.get(i).getKey()=="root.app.supplier.buy"||mAuthStatuses.get(i).getKey()=="root.app.supplier.sell"||mAuthStatuses.get(i).getKey()=="root.app.supplier.store.decoration")
                mAuthStatuses.remove(i);
        }
        int size = mAuthStatuses.size();
        int j = size % 4;

        if (j > 0) {
            j = 4 - j;
            for (int i = 0; i < j; i++) {
                AuthStatus as = new AuthStatus();
                as.setEmpty(true);
                mAuthStatuses.add(as);
            }


        }
    }


    public void onResume() {
        super.onResume();

    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onStop() {
        super.onStop();
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {


        }

    }


    public void updateTitleFlag(boolean isExpend) {
//        rotate(ivTitleFlag,isExpend);
        if (isExpend) {
            ivTitleFlag.setImageResource(R.mipmap.icon_home_down);
        } else {
            ivTitleFlag.setImageResource(R.mipmap.icon_home_up);
        }
    }

    private List<MerChantInfo> merChantInfoList = new ArrayList<>();
    MerchantListDialog merchantListDialog;

    private void expendTitle() {

        if (ivTitleFlag.getVisibility() != View.VISIBLE) {
            return;
        }

        if (merchantListDialog == null) {
            merchantListDialog = new MerchantListDialog(getContext());
            merchantListDialog.setOnDismissListener(new BaseDialogView.OnDismissListener() {
                @Override
                public void onDismiss(Object o) {
                    updateTitleFlag(false);
                }
            });
            merchantListDialog.setOnMerchantSwitch(new MerchantListDialog.OnMerchantSwitch() {
                @Override
                public void onMerchant(MerChantInfo merChantInfo) {
                    String name = merChantInfo.getName();
                    tvTitle.setText(name);
                    updateTitleFlag(false);
                    BaseApplication.getInstance().putMerchant(merChantInfo);
                    updateLoadToolbarTitle();

                    initNotice();//提示变价更新的对话框以及红点

                    reqMerchantList();


                }
            });
        }

        if (merchantListDialog.isShowing()) {
            merchantListDialog.dismiss();
            updateTitleFlag(false);
        } else {
            merchantListDialog.show(merChantInfoList);
            updateTitleFlag(true);
        }

    }

    private void updateToolbarTitle() {
        //更新权限
        updateAuth();
        MerChantInfo merchant = BaseApplication.getInstance().getMerchant();
        if(merchant.isAuthNeedBind()){//true 散货 false 整货
            rlOffer.setVisibility(View.GONE);
            ivOfferLitter.setVisibility(View.GONE);
        }else {
            rlOffer.setVisibility(View.VISIBLE);
            ivOfferLitter.setVisibility(View.VISIBLE);
        }
        String id = merchant.getId();
        if (id != null && !"".equals(id)) {
            tvTitle.setText(merchant.getNamePlus());
            vTitleTop.setVisibility(View.VISIBLE);
            updateMerchantInfo(merchant);
            ivTitleFlag.setVisibility(View.VISIBLE);
        } else {
            ivTitleFlag.setVisibility(View.INVISIBLE);
        }
    }

    private void updateLoadToolbarTitle() {
        FragmentActivity activity = getActivity();
        if (activity != null && activity instanceof HomeActivity) {
            Log.e("第1个up by f","1165");
           // ((HomeActivity) activity).updateBuyerStatus();
        }
        //更新权限
        updateAuth();
        MerChantInfo merchant = BaseApplication.getInstance().getMerchant();
        String id = merchant.getId();
        if (id != null && !"".equals(id)) {

            vTitleTop.setVisibility(View.VISIBLE);
            updateMerchantInfo(merchant);
            ivTitleFlag.setVisibility(View.VISIBLE);

            String status = merchant.getStoreStatus();
            //0,未开,1,开店,2,过,3,未过,4,冻结
            //未开店
            if ("0".equals(status)) {

                tvIntoStore.setVisibility(View.VISIBLE);
            } else {
                tvIntoStore.setVisibility(View.GONE);
            }
            tvTitle.setText(merchant.getNamePlus());
        } else {
            tvTitle.setText("未开店");
            vTitleTop.setVisibility(View.VISIBLE);
            tvIntoStore.setVisibility(View.VISIBLE);
            ivTitleFlag.setVisibility(View.INVISIBLE);
            updateAuthIcon();
        }
    }

    protected void updateAuth() {
       /* updateAuthOrder();
        updateAuthWriteOff();
        updateAuthCustomer();
        updateAuthStandingBook();*/

        if (!BaseApplication.getInstance().getMerchant().isEditPrice() || BaseApplication.getInstance().getMerchant().isAuthNeedBind()) {
            tvEditPrice.setAlpha(0.4f);
        } else {
            tvEditPrice.setAlpha(1f);
        }
        if (!BaseApplication.getInstance().getMerchant().isJoinPrepare()) {
            tvPrepare.setAlpha(0.4f);
            tvPrepareHint.setVisibility(View.GONE);
        } else {
            tvPrepare.setAlpha(1f);
        }
        if (!BaseApplication.getInstance().getMerchant().hasOfferAuth()) {
            tvOfferGet.setAlpha(0.4f);
        } else {
            tvOfferGet.setAlpha(1f);
        }
        if (!BaseApplication.getInstance().getMerchant().isWriteOff()) {
            tvWriteOff.setAlpha(0.4f);
        } else {
            tvWriteOff.setAlpha(1f);
        }
    }


    public void reqMerchantList() {

        if (getActivity() == null) {
            return;
        }
        updateTopInit();
        RequestEntityMapSupply RequestEntityMapSupply = new RequestEntityMapSupply();
        RequestEntityMapSupply.setCmd(AppSupplyRouterConstant.cmd_account_merchant_afterLogin);
        request(RequestEntityMapSupply, AppSupplyRouterConstant.cmd_account_merchant_afterLogin, onMerchantRequestListener);
    }

    private OnRequestListener<List<MerChantInfo>> onMerchantRequestListener = new OnRequestListener<List<MerChantInfo>>() {
        @Override
        public List<MerChantInfo> jsonToObj(String responseStr) {
            MerchantMember merchantMember = JsonUtils.fromJson(responseStr, MerchantMember.class);
            ArrayList<String> disabledResources = null;
            List<MerChantInfo> mcis = new ArrayList<MerChantInfo>();
            if (merchantMember != null&&merchantMember.getEmployees()!=null&&merchantMember.getEmployees().size()!=0) {//
                List<StaffInfo> list = merchantMember.getEmployees();
                disabledResources = merchantMember.getDisabledResources();

                if (list != null)
                    for (int i = 0; i < list.size(); i++) {
                        StaffInfo staffInfo = list.get(i);
                        if (staffInfo != null) {
                            MerChantInfo mc = staffInfo.getMerchant();
                            if (mc != null) {
                                staffInfo.setMerchant(null);

                                mc.setStaffInfo(staffInfo);
                                if (mc.isOwned()) {
                                    mc.setDisabledResources(disabledResources);
                                }
                                mcis.add(mc);
                            }
                        }
                    }

            }else {
                BaseApplication.getInstance().putMerchant(new MerChantInfo());
            }
            BaseApplication.getInstance().updateMerchants(mcis);
            BaseApplication.getInstance().putMerchantDisabledResources(disabledResources);
            return mcis;
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            if (getActivity() == null) {
                return;
            }
            ptrFrameLayout.refreshComplete();

        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            if (getActivity() == null) {
                return;
            }
            ptrFrameLayout.refreshComplete();

        }

        @Override
        public void onStart(Object tag) {
        }

        @Override
        public void onResponse(ResponseEntity<List<MerChantInfo>> response, Object tag) {
            if (getActivity() == null) {
                return;
            }
            ptrFrameLayout.refreshComplete();
            List<MerChantInfo> responseElement = response.getResponseElement();
            merChantInfoList.clear();
            if (responseElement != null)
                merChantInfoList.addAll(responseElement);

            updateLoadToolbarTitle();
            Log.e("first_________", "" +
                    "" + BaseApplication.getInstance().getStoreId());
            initNotice();//提示变价更新的对话框以及红点

            mItems.clear();
            mItems.add(new Integer(0));
            for(int i=mAuthStatuses.size()-1;i>0;i--){
                if (mAuthStatuses.get(i).getKey()=="root.app.supplier.buy"||mAuthStatuses.get(i).getKey()=="root.app.supplier.sell"||mAuthStatuses.get(i).getKey()=="root.app.supplier.store.decoration")
                    mAuthStatuses.remove(i);
            }
            mItems.addAll(mAuthStatuses);

            loadMoreDelegate.addAllItem(mItems, mOrderStoreDyns);
//            if (mOrderStoreDyns.size() == 0){
//                loadMoreDelegate.setStatusLoading();
//            }
            mMultiAdapter.notifyDataSetChanged();
            reqSupplyStoreDyn(0);

        }
    };

    private void reqSupplyStoreDyn(int pageNum) {
        if (getActivity() == null) {
            return;
        }

        RequestEntityMapSupply RequestEntityMapSupply = new RequestEntityMapSupply();
        RequestEntityMapSupply.setCmd(AppSupplyRouterConstant.cmd_order_supplier_order_dyn);

       /* "storeId": "",
        "pageNumber": "1",
        "pageSize": "10"*/
       if(BaseApplication.getInstance().getStoreId()==null||BaseApplication.getInstance().getMerchantId()==null)
           return;
        RequestEntityMapSupply.putParameter("storeId", BaseApplication.getInstance().getStoreId());
        RequestEntityMapSupply.putParameter("coId", BaseApplication.getInstance().getMerchantId());
        RequestEntityMapSupply.putParameter("pageNumber", pageNum);
        RequestEntityMapSupply.putParameter("pageSize", 15);
        request(RequestEntityMapSupply, AppSupplyRouterConstant.cmd_order_supplier_order_dyn, onSupplyStoreDynRequestListener);
    }

    private OnRequestListener<ContentEntity<OrderStoreDyn>> onSupplyStoreDynRequestListener = new OnRequestListener<ContentEntity<OrderStoreDyn>>() {
        @Override
        public ContentEntity<OrderStoreDyn> jsonToObj(String responseStr) {
            return JsonUtils.fromJsonObject(responseStr, ContentEntity.class, OrderStoreDyn.class);

        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            if (getActivity() == null) {
                return;
            }
            ptrFrameLayout.refreshComplete();

        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            if (getActivity() == null) {
                return;
            }
            ptrFrameLayout.refreshComplete();

        }

        @Override
        public void onStart(Object tag) {
        }

        @Override
        public void onResponse(ResponseEntity<ContentEntity<OrderStoreDyn>> response, Object tag) {
            if (getActivity() == null) {
                return;
            }
            ptrFrameLayout.refreshComplete();


            ContentEntity<OrderStoreDyn> responseElement = response.getResponseElement();


            boolean last = responseElement.getLast();

            int number = responseElement.getNumber();


            List<OrderStoreDyn> content = responseElement.getContent();

            //第一页
            if (number == 0) {
                mOrderStoreDyns.clear();
            }
            pageNum = number;
            if (content != null)
                mOrderStoreDyns.addAll(content);
//            mItems.add(content);
            mItems.clear();
            mItems.add(new Integer(0));
            mItems.addAll(mAuthStatuses);

            if (mOrderStoreDyns.size() == 0) {
                loadMoreDelegate.setStatusEmpty();
                loadMoreDelegate.addLoadItemOnly(mItems);
            } else {
                loadMoreDelegate.addAllItem(mItems, mOrderStoreDyns);
                //最后一个
                if (last) {
                    loadMoreDelegate.setStatusNoMore();
                } else {
                    loadMoreDelegate.setStatusNormal();
                }
            }
            mMultiAdapter.notifyDataSetChanged();

        }
    };

    void initNotice() {
        RequestEntityMapSupply RequestEntityMapSupply = new RequestEntityMapSupply();
        RequestEntityMapSupply.setCmd(com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_product_noticeWord);
        if (BaseApplication.getInstance().getStoreId() == null)
            return;
        RequestEntityMapSupply.putParameter("storeId", BaseApplication.getInstance().getStoreId());
        RequestTag rt = new RequestTag();
        rt.tag = com.epfresh.api.constant.AppSupplyRouterConstant.cmd_store_product_noticeWord;
        rt.type = RequestTag.TYPE_CURRENT;
        request(RequestEntityMapSupply, rt, noticeRequestListener);
    }

    Date currentTime = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String dateString = formatter.format(currentTime);

    OnRequestListener<PriceNoticeEntity> noticeRequestListener = new OnRequestListener<PriceNoticeEntity>() {
        @Override
        public PriceNoticeEntity jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, PriceNoticeEntity.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {


        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {


        }

        @Override
        public void onStart(Object tag) {

        }

        @Override
        public void onResponse(ResponseEntity<PriceNoticeEntity> response, Object tag) {
            SharedPreferences sp = getContext().getSharedPreferences("notice_time", Context.MODE_PRIVATE);
            updateMsgPrice(0);
            updateMsgOffer(0);
            tvPrepareHint.setVisibility(View.GONE);
            if (response != null) {
                DataManager.getInstance().clearPriceGoods();
                PriceNoticeEntity responseElement = response.getResponseElement();
                updateJoinPrice = responseElement.getUpdateJoinPrice();
                updateMsgOffer(responseElement.getOfferCnt());
                if(responseElement.getJointOrderTime()==null||responseElement.getJointOrderTime().length()<18){
                    tvPrepareHint.setVisibility(View.GONE);
                }else {
                    long tEnd = DateUtil.formatTimeLong(responseElement.getJointOrderTime());
                    long tLocale = System.currentTimeMillis();
                    if(tEnd>tLocale) {
                        tvPrepareHint.setText("最晚" + (responseElement.getJointOrderTime().substring(11, 16)));
                        if (BaseApplication.getInstance().getMerchant().isJoinPrepare())
                            tvPrepareHint.setVisibility(View.VISIBLE);
                        else {
                            tvPrepareHint.setVisibility(View.GONE);
                        }
                    }else{
                        tvPrepareHint.setVisibility(View.GONE);
                    }
                }


                if (responseElement.isShow()) {////show???
                    updateMsgPrice(1);
                    if (!"".equals(responseElement.getNoticeMessage()) && !sp.getString("home_show_flag", "1").equals(dateString)) {
                        final HomePriceNoticeDialog dialog = new HomePriceNoticeDialog(getContext());
                        dialog.setOnSureListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
/*                                Intent intent = new Intent(getAppActivity(), ChangePriceActivity.class);
                                startActivityForResult(intent, 0x002);*/
                                intoEditPrice();
                                dialog.dismiss();
                            }
                        });
                        dialog.show(response.getResponseElement().getNoticeMessage());
                        sp.edit().putString("home_show_flag", dateString).commit();
                    }
                } else {
                    updateMsgPrice(0);
                    if (!"".equals(responseElement.getUpdateMessage()) && !sp.getString("home_show_flag", "1").equals(""/*dateString*/)) {
                        //updateNotice(responseElement.getUpdateMessage());
                        //sp.edit().putString("show_flag", dateString).commit();
                    } else {
                        //updateNotice("");
                    }
                }
            }
        }
    };


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 0x002) {// && resultCode == 0x001) {
            initNotice();
        }
        super.onActivityResult(requestCode, resultCode, data);

    }
}
